//
//  MCBlock.m
//  Block
//
//  Created by yangyang38 on 2018/3/5.
//  Copyright © 2018年 yangyang. All rights reserved.
//

#import "MCBlock.h"

@interface MCBlock (){
    __weak NSString *_myString;
}

@property (nonatomic, strong) int(^TestBlock)(int);

@end

@implementation MCBlock

// 全局变量
int global_var = 4;
// 静态全局变量
static int static_global_var = 5;

- (void)method
{
    static int multiplier = 6;
    int(^Block)(int) = ^int(int num)
    {
//        __block
        return num * multiplier;
    };
    multiplier = 4;
    NSLog(@"result is %d", Block(2));
}

- (void)testBlock {
    __block int multiplier = 10;
    self.TestBlock = ^int(int num) {
        return num *multiplier;
    };
    multiplier = 4;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self executeBlock];
    });
    
    _myString = @"12345";
}

- (void)executeBlock {
    int result = self.TestBlock(4);
    NSLog(@"result is %d",result);
}
@end
